#pragma once
#include "stdafx.h"
#include <string>
#include <sstream>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/PlatformUtils.hpp>
using namespace std;
using namespace xercesc;

class CHelper
{
public:
	static double string_to_double(string s)
	{
		istringstream instr(s);
		double x;
		instr >> x;
		return x;
	}

	static int string_to_int(string s)
	{
		istringstream instr(s);
		int x;
		instr >> x;
		return x;
	}

	static string XMLCh_to_string(const XMLCh* arr)
	{
		char* s = XMLString::transcode(arr);
		string r(s);
		XMLString::release(&s);
		return r;
	}

	static double XMLCh_to_double(const XMLCh* arr)
	{
		char* s = XMLString::transcode(arr);
		string r(s);
		XMLString::release(&s);
		return string_to_double(r);
	}

	static int XMLCh_to_int(const XMLCh* arr)
	{
		char* s = XMLString::transcode(arr);
		string r(s);
		XMLString::release(&s);
		return string_to_int(r);
	}

	static string GetAttributeValue( DOMElement* element, string attributeName ) 
	{
		XMLCh* xtext = new XMLCh[attributeName.length() + 1];
		XMLString::transcode(attributeName.c_str(), xtext, attributeName.length());
		const XMLCh* val = element->getAttribute(xtext);
		delete xtext;
		return XMLCh_to_string(val);
	}


};

